<script setup>
import {computed} from "vue";
import GlobalParas from "@/GlobalParas.js";

let props = defineProps({
  file: {
    type: Object,
    default: {
      fileName: " ",
      serverFileName: " "
    }
  }
})

let fileType = computed(function () {
  let typeIndex = props.file.fileName.lastIndexOf(".");
  let type = props.file.fileName.substring(typeIndex).toLowerCase();
  let returnType = type;

  let imgType = ".jpg,.jpeg,.bmp,.png,.gif,.tif,.svg,.eps"
  if (imgType.indexOf(type) !== -1) {
    returnType = ".img"
  }

  switch (type) {
    case ".zip":
      returnType = ".rar"
      break;
    case ".7z":
      returnType = ".rar"
      break;
    case ".tgz":
      returnType = ".rar"
      break;
    case ".docx":
      returnType = ".doc"
      break;
    case ".doc":
      returnType = ".doc"
      break;
    default:
      break;
  }

  return returnType;
})

let filePath = computed(function () {
  return GlobalParas.downLoadPath + props.file.serverFileName;
})
</script>

<template>
  <a :href="filePath" target="_blank" :title="props.file.fileName">
    <img v-if="fileType==='.txt'" class="iconClass" src="./KingFileImg/txt.png" :alt="props.file.fileName"/>
    <img v-else-if="fileType==='.rar'" class="iconClass" src="./KingFileImg/rar.png" :alt="props.file.fileName"/>
    <img v-else-if="fileType==='.pdf'" class="iconClass" src="./KingFileImg/pdf.png" :alt="props.file.fileName"/>
    <img v-else-if="fileType==='.doc'" class="iconClass" src="./KingFileImg/word.png" :alt="props.file.fileName"/>
    <img v-else-if="fileType==='.img'" class="iconClass" :src="filePath" :alt="props.file.fileName"/>
    <img v-else class="iconClass" src="./KingFileImg/att.png" :alt="props.file.fileName"/>
  </a>
</template>

<style scoped>
.iconClass {
  width: 60px;
  height: 60px;
}
</style>